package kisti.gui.CDF;

import java.awt.Color;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

import daniel.kisti.Helper.Caf_Helper;





/**
 * <pre>
 * kisti.gui.CDF
 *   |_ CAF_JobMon.java
 *
 * </pre>
 *
 * Desc : cdf job 을 그래프 테이블 형식으로 그려 패널을 생성한다. 
 * @Company : KISTI
 * @Author :daniel
 * @Date   :2011. 11. 14. 오후 5:10:09
 * @Version:
 *
 */
public class CAF_JobMon extends JPanel{

    private JTable table;
//    private String[] jobTableheader ;
    private String[][] jobTablecells;
    private Caf_Helper cafHelper;
    
    /**
     * 
     * Desc : Constructor of WorkerNodeStatus.java class
     */
	public CAF_JobMon() {
		// TODO Auto-generated constructor stub		
		cafHelper = new Caf_Helper();
		
		String[] jobTableheader = { "Month", "Period", "Users", "Jobs(Total)",
				"Success", "RatioSucessJob", "totalWallTime", "successWallTime", "ratioSucessWallTime", "Status" };		
		jobTablecells = cafHelper.getJobStatus(); 
		
		
		table = new JTable(jobTablecells, jobTableheader);
		table.setBackground(new Color(255, 255, 204));
		

		/**
		 * 셀 간격 조정
		 */
		DefaultTableCellRenderer celAlignCenter = new DefaultTableCellRenderer();
		celAlignCenter.setHorizontalAlignment(JLabel.CENTER);
		DefaultTableCellRenderer celAlignRight = new DefaultTableCellRenderer();
		celAlignRight.setHorizontalAlignment(JLabel.RIGHT);
		
		/**
		 *  각 셀의 넓이 와 정렬
		 */
		table.getColumn("Month").setPreferredWidth(10);
		table.getColumn("Month").setCellRenderer(celAlignCenter);
		table.getColumn("Period").setPreferredWidth(120);
		table.getColumn("Period").setCellRenderer(celAlignCenter);
		table.getColumn("Users").setPreferredWidth(5);
		table.getColumn("Users").setCellRenderer(celAlignCenter);
		table.getColumn("Jobs(Total)").setPreferredWidth(30);
		table.getColumn("Jobs(Total)").setCellRenderer(celAlignRight);
		table.getColumn("Success").setPreferredWidth(30);
		table.getColumn("Success").setCellRenderer(celAlignRight);
		table.getColumn("RatioSucessJob").setPreferredWidth(10);
		table.getColumn("RatioSucessJob").setCellRenderer(celAlignRight);
		
		
		table.getColumn("totalWallTime").setPreferredWidth(30);
		table.getColumn("totalWallTime").setCellRenderer(celAlignRight);
		table.getColumn("successWallTime").setPreferredWidth(30);
		table.getColumn("successWallTime").setCellRenderer(celAlignRight);
		table.getColumn("ratioSucessWallTime").setPreferredWidth(10);
		table.getColumn("ratioSucessWallTime").setCellRenderer(celAlignRight);
		
		
		table.getColumn("Status").setPreferredWidth(10);		

		
		this.setBackground(Color.WHITE);
		this.setLayout(null);
		JScrollPane jspWN = new JScrollPane(table);
		jspWN.setBounds(0, 0, 569, 206);
		this.add(jspWN);// JScrollPanel을 사용하지 않으면 헤더가 보이지 않는다!!
	}

	
	
	
	
	
	
	
	
	
    /**
     * @param args
     */
    public static void main(String[] args) {
            // TODO Auto-generated method stub
            JFrame f = new JFrame();
            CAF_JobMon w = new CAF_JobMon();
            f.add(w);
            f.setSize(650,400);
            f.setVisible(true);
            
            f.addWindowListener(new WindowAdapter() {
    			public void windowClosing(WindowEvent e) {
    				System.exit(0);
    			}

    			public void windowDeiconified(WindowEvent e) {
    				System.out.println("windowDeiconified");
    			}

    			public void windowIconified(WindowEvent e) {
    				System.out.println("windowIconified");
    			}
    		});
    }
}
